Skip to content

Add avoid_direct_collection_equality_checks lint - #546

Merged
cupofme merged 10 commits into
masterfrom
feature/avoid_direct_collection_equality_checks-lint
Aug 5, 2026
Merged

Add avoid_direct_collection_equality_checks lint#546
cupofme merged 10 commits into
masterfrom
feature/avoid_direct_collection_equality_checks-lint

Conversation

@cupofme

@cupofme cupofme commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Comparing collections with ==/!= in Dart checks identity, not contents — so [1, 2] == [1, 2] is false. It's an easy mistake to make and a painful one to debug, since the code reads like it should work.

This adds a lint that flags direct ==/!= comparisons between List, Set, or Map values (and their subtypes) when both sides are the same kind of collection.

Each warning comes with two quick fixes:

  • listEquals(a, b) / setEquals / mapEquals from package:flutter/foundation.dart
  • const ListEquality<int>().equals(a, b) / SetEquality / MapEquality from package:collection

The messages and fix names adapt to the collection type (e.g. it suggests listEquals for a list, mapEquals for a map), and the package:collection fix fills in the type argument so you don't get an inference warning afterwards.

Screen.Recording.2026-07-15.at.16.30.20.mov

@cupofme
cupofme requested a review from mchudy as a code owner July 15, 2026 14:28
@github-actions github-actions Bot added the p: leancode_lint Related to the leancode_lint package label Jul 15, 2026
Comment thread packages/leancode_lint/lib/src/lints/avoid_direct_collection_equality_checks.dart Outdated
Comment thread packages/leancode_lint/lib/src/lints/avoid_direct_collection_equality_checks.dart Outdated
Comment thread packages/leancode_lint/lib/src/lints/avoid_direct_collection_equality_checks.dart Outdated
Comment thread packages/leancode_lint/README.md
Comment thread packages/leancode_lint/lib/src/lints/avoid_direct_collection_equality_checks.dart Outdated
Comment thread packages/leancode_lint/lib/src/lints/avoid_direct_collection_equality_checks.dart Outdated
Comment thread packages/leancode_lint/lib/src/lints/avoid_direct_collection_equality_checks.dart Outdated
@cupofme
cupofme requested a review from PiotrRogulski July 27, 2026 11:01
Comment thread packages/leancode_lint/lib/src/lints/avoid_direct_collection_equality_checks.dart Outdated
Comment thread packages/leancode_lint/lib/src/lints/avoid_direct_collection_equality_checks.dart Outdated
Comment thread packages/leancode_lint/lib/src/lints/avoid_direct_collection_equality_checks.dart Outdated
@cupofme
cupofme requested a review from PiotrRogulski August 5, 2026 10:03
@override
List<String>? get fixArguments {
final binary = _targetBinary(node);
final kind = binary == null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do binary! as well in these fixArguments getters

@cupofme
cupofme merged commit a935973 into master Aug 5, 2026
2 checks passed
@cupofme
cupofme deleted the feature/avoid_direct_collection_equality_checks-lint branch August 5, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: leancode_lint Related to the leancode_lint package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants